﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RainyPWS.Business;
using RainyPWS.Model;
using System.Web.Security;

namespace RainyPWS.Web.Admin
{
    public partial class Login1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSubmit.Click += new EventHandler(btnSubmit_Click);

        }

        void btnSubmit_Click(object sender, EventArgs e)
        {
            string userName = txtUserName.Text;
            string Password = txtPassword.Text;
            MUser user = BUser.Instance.GetUserByUserCode(userName);
            if (user.ID != 0 && user.Password == Password)
            {
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, userName, DateTime.Now, DateTime.Now.AddHours(1), false, user.Level.ToString(), FormsAuthentication.FormsCookiePath);
                string enTicket = FormsAuthentication.Encrypt(ticket);
                Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, enTicket));
                Response.Redirect(FormsAuthentication.GetRedirectUrl(userName, true));
            }
        }
    }
}